package com.example.mybatisplus.exception;

import com.example.mybatisplus.vo.ResultBean;
import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

@RestControllerAdvice
/**
 * 如果是自己异常就填写自己的异常信息，不是自己那就是服务器的异常信息
 */
public class GlobalExceptionHandler {

    @ExceptionHandler(value = Exception.class)
    public ResultBean exceptionHandler(Exception e){
        e.printStackTrace();
        if (e instanceof AppException){
            AppException appException = (AppException)e;
            return ResultBean.ERROR(appException.getCode(),appException.getMessage());
        }
        return ResultBean.ERROR();
    }
}
